package com.awspaas.user.apps.cpq.event;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;

public class Test extends ExecuteListener{

	@Override
	public void execute(ProcessExecutionContext arg0) throws Exception {
	       try (FileInputStream fis = new FileInputStream("F:/tempXJRCPQ/123.xlsx");
	               Workbook workbook = new XSSFWorkbook(fis)) {
	              
	              Sheet sheet = workbook.getSheetAt(0);
	              
	              for (Row row : sheet) {
	                  for (Cell cell : row) {
	                      if (cell.getCellType() == CellType.STRING && 
	                          cell.getStringCellValue().equals("笼架系统")) {
	                          
	                          // 获取右侧单元格，如果不存在则创建
	                          Cell rightCell = row.getCell(cell.getColumnIndex() + 4);
	                          if (rightCell == null) {
	                              rightCell = row.createCell(cell.getColumnIndex() + 4);
	                          }
	                          
	                          rightCell.setCellValue("12345678");
	                      }
	                  }
	              }
	              
	              // 保存修改后的文件
	              try (FileOutputStream fos = new FileOutputStream("F:/tempXJRCPQ/123.xlsx")) {
	                  workbook.write(fos);
	              }
	              
	          } catch (Exception e) {
	              e.printStackTrace();
	          }
		
	}

}
